import { runtimeConfig } from '../configs/runtimeConfig'

/**
 * 给filepath前面拼接baseUrl
 * @param filepath 以/开头的文件路径，例如/uploads/avatar/abcd.jpg
 * @returns
 */
export const toUrl = (filepath: string) => {
    const baseUrl = runtimeConfig.urlConfigs.uploadBaseUrl
    return `${baseUrl}${filepath}`
}

/**
 * 从url中移除 baseUrl + '/'
 * @param url 含有baseUrl的文件路径
 * @returns 非/开头的文件路径，例如uploads/avatar/abcd.jpg
 */
export const toFilepath = (url: string) => {
    const baseUrl = runtimeConfig.urlConfigs.uploadBaseUrl
    return url.replace(baseUrl + '/', '')
}
